package com.team.employment.web.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.team.employment.model.entity.CompanyInfo;
import com.team.employment.model.entity.CompanyType;
import com.team.employment.web.admin.mapper.CompanyInfoMapper;
import com.team.employment.web.admin.service.CompanyTypeService;

import com.team.employment.web.admin.mapper.CompanyTypeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;


@Service
public class CompanyTypeServiceImpl extends ServiceImpl<CompanyTypeMapper, CompanyType>
    implements CompanyTypeService{

    @Autowired
    private CompanyTypeMapper companyTypeMapper;

    @Autowired
    private CompanyInfoMapper companyInfoMapper;

    @Override
    public List<CompanyInfo> getTypeById(Long id) {
        LambdaQueryWrapper<CompanyType> typeLambdaQueryWrapper = new LambdaQueryWrapper<>();
        typeLambdaQueryWrapper.eq(CompanyType::getId,id);
        List<CompanyType> companyTypes = companyTypeMapper.selectList(typeLambdaQueryWrapper);
        List<Long> companyIds = companyTypes.stream().map(CompanyType::getCompanyId).collect(Collectors.toList());

        LambdaQueryWrapper<CompanyInfo> infoLambdaQueryWrapper = new LambdaQueryWrapper<>();
        infoLambdaQueryWrapper.in(CompanyInfo::getId,companyIds);
        List<CompanyInfo> companyInfos = companyInfoMapper.selectList(infoLambdaQueryWrapper);
        return companyInfos;
    }
}




